﻿using MediatR;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
using Yitter.IdGenerator;

namespace U.Enterprise.Api.Applications.BatchManagements
{
    public class BulkSlaughterCreateHander : IRequestHandler<BulkSlaughterCreateCommand, Resqults>
    {
        private readonly IBateRepository<BulkSlaughter> bulk;

        public BulkSlaughterCreateHander(IBateRepository<BulkSlaughter> bulk)
        {
            this.bulk = bulk;
        }

        public async Task<Resqults> Handle(BulkSlaughterCreateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults res = new Resqults() { Code=0};
                List<BulkSlaughter> list= request.list;
                foreach (var item in list)
                {
                    item.DocumentsNo=YitIdHelper.NextId().ToString();
                }
                res.Code = await bulk.AddRang(list);
                if (res.Code > 0)
                {
                    res.Messges = "成功";
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
